<template>
  <div class="remindInput">
    <div class="left">
      <div class="detail_main">
        <div class="detail_top">
          <h2>监控信息</h2>
        </div>
        <div class="detail_containter">
          <div class="tsxx-wrpa">
            <div v-for="item in tiShiInfo" :key="item.MESSAGE">({{ item.REMIND_ID }}) {{ item.MESSAGE }}</div>
          </div>
          <FilterTable
            ref="basetable1"
            :columns="columns1"
            :dataSource="dataSource"
            :onColumnsChange="columns1 => (this.columns1 = columns1)"
            :height="100"
            :isColumnFilter="false"
            :isSelectColumn="false"
            :isPagination="false"
          ></FilterTable>
        </div>
      </div>
      <div class="detail_main">
        <div class="detail_top">
          <h2>工单历史</h2>
        </div>
        <div class="detail_containter">
          <FilterTable
            ref="basetable2"
            :fetchapi="fetchApi2"
            :columns="columns2"
            :params="fetchParams2"
            :datakey="'rows'"
            :height="120"
            :onColumnsChange="columns2 => (this.columns2 = columns2)"
            :onSyncTableData="getRepairType"
            :isColumnFilter="false"
            :isSelectColumn="false"
          ></FilterTable>
        </div>
      </div>
      <div class="detail_main">
        <div class="detail_top">
          <h2>服务活动</h2>
        </div>
        <div class="detail_containter">
          <FilterTable
            ref="basetable3"
            :columns="columns3"
            :dataSource="dataSource3"
            :height="150"
            :onColumnsChange="columns3 => (this.columns3 = columns3)"
            :isPagination="false"
            :isColumnFilter="false"
            :isSelectColumn="false"
          ></FilterTable>
        </div>
      </div>
    </div>

    <div class="right">
      <div class="detail_main">
        <div class="detail_top">
          <h2>提醒信息</h2>
        </div>
        <div class="detail_containter">
          <FormPanel :list="formList2" :isSubmitBtn="false" :collapse="false" :labelWidth="120" @formChange="changeHandle2" />
          <ButtonArea :style="{ paddingLeft: '0px', float: 'right' }">
            <el-button type="primary" icon="el-icon-printer" @click="monitoringBtnFun()">监控信息</el-button>
            <el-button type="primary" @click="showDia(1)">投诉历史</el-button>
            <el-button type="primary" @click="showDia(2)">维修历史</el-button>
            <el-button type="primary" @click="openRemindHistory()">提醒历史</el-button>
            <el-button type="primary" @click="showDia(3)">维修建议</el-button>
          </ButtonArea>
          <div style="clear:both;">
            <ToggleTable v-if="type == 1" ref="ToggleTable" :data="this.remindData"></ToggleTable>
            <ToggleText v-if="type == 2" ref="toggleText" :data="this.remindData" :remindSourcePath="this.remindSource"></ToggleText>
          </div>
          <div
            :style="{
              position: 'absolute',
              left: 0,
              bottom: 0,
              right: 0,
              zIndex: 9999,
              borderTop: '1px solid #e9e9e9',
              padding: '10px 20px',
              background: '#fff',
              textAlign: 'right'
            }"
          >
            <el-button type="primary" @click="showDia(4)">预约安排</el-button>
            <el-button @click="saveMsg">{{ isTrace === 80581003 || isTrace === 80581004 ? '确定' : '保存' }}</el-button>
            <el-button @click="closeDialog">取 消</el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 监控 -->
    <Drawer :visible.sync="ismonitoring" title="监控车辆提醒" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <!-- isBtnAtion: 是否自动弹出; queryParams: 传入参数(格式见 props 内定义); confirm: 确定事件(选择的 活动，预约) -->
      <MonitoringModal :isAutoAtion="isMonitoringAutoAtion" :queryParams="monitoringQueryParams" @confirm="monitoringConfirm" @cancel="ismonitoring = false" />
    </Drawer>

    <!-- 投诉历史 -->
    <Drawer :visible.sync="showComplaintHistory" title="投诉历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <complaintHistory ref="complaintHistory" :vin="chooseVin" @close="cancle(1)"></complaintHistory>
    </Drawer>

    <!-- 维修历史 -->
    <Drawer :visible.sync="showRepairHistory" title="维修历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <repairHistory ref="repairHistory" :getdata="repairHistoryData" @close="cancle(2)"></repairHistory>
    </Drawer>

    <!-- 提醒历史 -->
    <Drawer :visible.sync="showRemindHistory" title="提醒历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <RemindHistory :vin="chooseVin" :ownerNo="chooseOwnerNo" :remindSource="2" @close="closeRemindHistory" />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9999,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="closeRemindHistory">返 回</el-button>
      </div>
    </Drawer>

    <!-- 维修建议 -->
    <Drawer :visible.sync="showRepairSuggest" title="维修建议" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <!-- <RepairImport ref="RepairImport" :vin="chooseVin" @cancel="cancle(3)" /> -->
    </Drawer>

    <!-- 预约安排 -->
    <Drawer :visible.sync="showReservation" title="预约安排" width="1350" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Precontract ref="Precontract" :Vin="chooseVin" :License="chooseLicense" @close="cancle(4)" />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9999,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="cancle(3)">返 回</el-button>
      </div>
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import ToggleTable from '@/pages/customerRepair/customerCare/maintenanceRemind/ToggleTable';
import ToggleText from '@/pages/customerRepair/customerCare/maintenanceRemind/toggleText';
import { queryRepairBusiness } from '@/api/repair/repairReception/repairBusinessManger';
import { retriveByControl, retriveByControlright, queryActivityValid } from '@/api/repair/repairReception/customer/monitoring.js';
import { addRemind, addQuestion } from '@/api/customerRepair/customerCare/maintenanceRemind';
// import { getfindAllRepairType } from '@/api/repair/repairReception/customer/history';
import RemindHistory from '@/pages/customerRepair/customerCare/vehicleRemind/components/remindHistory.vue';
import MonitoringModal from '@/pages/customerRepair/customerCare/maintenanceRemind/monitoring/Modal.vue';
import complaintHistory from '@/pages/repair/business/customer/combination/complaint';
import repairHistory from '@/pages/repair/business/customer/Repairhistory/historypop.vue';
// import RepairImport from '@/pages/repair/repairReception/customer/repairImport/Modal.vue';
import Precontract from '@/pages/repair/repairReception/precontractArrange';
import { getModel } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';
export default {
  name: 'remindInputs',
  components: {
    ToggleTable,
    ToggleText,
    RemindHistory,
    MonitoringModal,
    complaintHistory,
    repairHistory,
    // RepairImport,
    Precontract
  },
  mixins: [dictionary],
  // props: {
  //   remindData: {
  //     type: Object,
  //     default: () => ({})
  //   }
  // },
  props: ['remindData', 'buttonType', 'remindSource'],
  data() {
    return {
      type: this.buttonType || 2,
      ismonitoring: false, // 监控
      isMonitoringAutoAtion: false,
      monitoringQueryParams: {},
      // 提示信息
      tiShiInfo: [],
      // 提示信息 监控表格
      dataSource: [],
      dataSource3: [], //  服务活动
      formList1: this.createdFrom1(),
      formList2: this.createdFrom2(),
      // formList3: this.createdFrom3(),
      fetchApi2: queryRepairBusiness,
      fetchParams2: { xhrAbort: true },
      columns1: this.createdTable1(),
      columns2: this.createdTable2(),
      columns3: this.createdTable3(),
      dataList2: [],
      showRemindHistory: false,
      isTrace: null,
      chooseVin: null, // 选中的vin
      chooseLicense: null, // 选中的license
      chooseOwnerNo: null, // 选中的数据的ownerNo
      repairHistoryData: {}, // 维修历史数据
      showRepairHistory: false, // 维修历史
      showRepairSuggest: false, // 建议维修
      showComplaintHistory: false, // 投诉历史
      showReservation: false, // 预约安排
      remindSourcePath: null, // 数据来源
      isMustFlag: true,
      flag: true
    };
  },
  created() {},
  mounted() {
    console.log(this.remindData, 'data');
    console.log(this.remindSource, 'this.remindSource');
    this.$nextTick(() => {
      this.remindSourcePath = this.remindSource;
    });
    this.typeSelect();
    this.queryEmpolyeeInfo();
    this.getMonitoryTable();
    this.getRepairHistoryTable();
    this.queryActivityValid();
    this.initForm2();
    this.isTrace = this.remindData.TRACE_STATUS;
    this.queryModel();
  },
  methods: {
    createdFrom1() {
      return [
        {
          type: 'TEXT_AREA',
          label: '提醒内容',
          fieldName: 'DEALER_CODE',
          initialValue: ''
        }
      ];
    },

    monitoringFunBefore() {
      // const vowner = {};
      // this.remindData.forEach((item, i) => {
      //   vowner[item.fieldName] = item.initialValue;
      // });
      this.monitoringQueryParams = {
        MODEL: this.remindData.model,
        SERIES: this.remindData.series,
        // 活动 出险 预约 新能源 参数
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        BRAND: this.remindData.brand,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        dmsFuncId: '35100010',
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        _: new Date().getTime()
      };
    },

    monitoringAutoFun() {
      this.isMonitoringAutoAtion = true;
      this.monitoringFunBefore();
      this.ismonitoring = true;
    },
    monitoringBtnFun() {
      this.isMonitoringAutoAtion = false;
      this.monitoringFunBefore();
      this.ismonitoring = true;
    },

    monitoringConfirm(obj) {
      // console.log('监控选择的', obj);
      this.ismonitoring = false;
    },

    // 显示弹框
    showDia(type) {
      this.chooseVin = this.remindData.vin;
      this.chooseLicense = this.remindData.license;
      this.chooseOwnerNo = this.remindData.owner_no;
      switch (type) {
        case 1:
          // 打开投诉历史
          this.showComplaintHistory = true;
          break;
        case 2:
          // 打开维修历史
          this.repairHistoryData = {
            LICENSE: this.remindData.license,
            VIN: this.remindData.vin,
            ENGINE_NO: this.remindData.engine_no,
            OWNER_NAME: this.remindData.owner_name
          };
          this.showRepairHistory = true;
          break;
        case 3:
          // 打开建议维修
          this.showRepairSuggest = true;
          break;
        case 4:
          // 打开预约安排
          this.showReservation = true;
          break;
      }
    },

    // 取消,关闭弹框
    cancle(type) {
      switch (type) {
        case 1:
          // 关闭投诉历史
          this.showComplaintHistory = false;
          break;
        case 2:
          // 关闭维修历史
          this.showRepairHistory = false;
          break;
        case 3:
          // 关闭建议维修
          this.showRepairSuggest = false;
          break;
        case 4:
          // 关闭预约安排
          this.showReservation = false;
          break;
      }
    },

    initForm2() {
      let newStr = [];
      for (let [key, val] of Object.entries(this.remindData)) {
        let param = {
          fieldName: key,
          value: val
        };
        newStr.push(param);
      }
      this.syncFormListData(newStr);
    },

    // 驼峰转换  RO_NO --> roNo
    camelcase(str) {
      let arr = str.split('_');
      let upper = arr.map((val, index) => {
        let lowStr = val.toLowerCase();
        if (index) {
          lowStr = lowStr.charAt(0).toLocaleUpperCase() + lowStr.slice(1);
        }
        return lowStr;
      });
      return upper.join('');
    },

    // 把返回的数据赋值给表单
    syncFormListData(dataList) {
      const formList = [...this.formList2];
      const formFieldNames = formList.map(x => x.fieldName);
      dataList.forEach(x => {
        if (formFieldNames.includes(x.fieldName)) {
          let target = formList.find(k => k.fieldName == x.fieldName);
          if (!target) return;
          target.initialValue = x.value;
        }
      });
    },
    createdFrom2() {
      return [
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'ownerName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修人',
          fieldName: 'deliverer',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主电话',
          fieldName: 'phone',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修人电话',
          fieldName: 'delivererPhone',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'model',
          initialValue: '',
          itemList: [],
          disabled: true
        },
        {
          type: 'SELECT',
          label: '上次接待顾问',
          fieldName: 'lastConsultantId',
          initialValue: '',
          itemList: [],
          disabled: true
        },
        {
          type: 'DATE',
          label: '保险到期日期',
          fieldName: 'insuranceDate',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '保险公司',
          fieldName: 'insuranceCompany',
          initialValue: '',
          disabled: true
        },
        {
          type: 'DATE',
          label: '本店最近购买保险日',
          fieldName: 'latestBuyInsuranceDate',
          disabled: true
        }
      ];
    },

    createdTable1() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '监控信息',
          dataIndex: 'MESSAGE',
          sorter: true,
          filter: true
        }
      ];
    },
    createdTable2() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          filterItems: []
        },
        {
          title: '开单日期',
          dataIndex: 'RO_CREATE_DATE',
          sorter: true,
          filter: true
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true
        },
        {
          title: '材料费',
          dataIndex: 'REPAIR_PART_AMOUNT',
          sorter: true,
          filter: true
        },
        {
          title: '维修总金额',
          dataIndex: 'REPAIR_AMOUNT',
          sorter: true,
          filter: true
        }
      ];
    },
    createdTable3() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{props.row.ACTIVITY_CODE}</span>;
          // }
        },
        {
          title: '活动名称',
          dataIndex: 'ACTIVITY_NAME',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{props.row.ACTIVITY_NAME}</span>;
          // }
        },
        {
          title: '活动类型',
          dataIndex: 'ACTIVITY_TYPE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.ACTIVITY_TYPE, '8080')}</span>;
          }
        },
        {
          title: '开始日期',
          dataIndex: 'startTime',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.startTime}</span>;
          }
        },
        {
          title: '结束日期',
          dataIndex: 'END_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
          // render: props => {
          //   return <span>{props.row.END_DATE}</span>;
          // }
        },
        {
          title: '活动总金额',
          dataIndex: 'ACTIVITY_AMOUNT',
          sorter: true,
          filter: true
        }
      ];
    },
    changeHandle1(val) {},
    changeHandle2(val) {},
    changeHandle3(val) {},

    async getRepairType(val) {
      let res = await getfindAllRepairType();
      // console.log(res,'res')
      let arr = [];
      res.data.forEach(x => {
        arr.push({ text: x.REPAIR_TYPE_NAME, value: x.REPAIR_TYPE_CODE });
      });
      val.forEach(x => {
        arr.forEach(y => {
          if (x.REPAIR_TYPE_CODE == y.value) {
            // console.log(y);
            x.REPAIR_TYPE_CODE = y.text;
          }
        });
      });
    },

    // 页面管控
    typeSelect() {
      this.formList2.map(x => {
        x.disabled = true;
      });
    },
    // 查询所有车型
    async queryModel() {
      const res = await getModel();
      console.log(res, 'res');
      this.formList2.find(x => x.fieldName === 'model').itemList = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));
      const resUser = await getDealerUser();
      // 服务顾问
      this.formList2.find(x => x.fieldName === 'lastConsultantId').itemList = resUser.data.map(x => ({ value: x.userId, text: x.employeeName }));
    },

    openRemindHistory(data) {
      this.showRemindHistory = true;
    },

    // 关闭历史提醒
    closeRemindHistory(data) {
      this.showRemindHistory = false;
    },

    // 提醒内容
    async queryEmpolyeeInfo() {
      // console.log(this.remindData,'shuju')
      this.chooseOwnerNo = this.remindData.ownerNo;
      this.chooseVin = this.remindData.vin;

      let obj = {
        vin: this.remindData.vin,
        LICENSE: this.remindData.license
      };
      const res = await retriveByControl(obj);
      // console.log(res,'neirong')
      this.tiShiInfo = res.data;
    },

    // 查询 监控信息
    async getMonitoryTable() {
      const params = {
        sort: 'IS_VALID',
        order: 'asc',
        engineNo: this.remindData.engineNo || '',
        MODEL: this.remindData.modelCode || '',
        SERIES: this.remindData.seriesCode || '',
        RONO: this.remindData.roNo || '',
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        BRAND: this.remindData.brandCode || '',
        MILEAGE: this.remindData.lastMaintainMileage,
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        dmsFuncId: '35100010',
        _: '1567144192282'
      };
      const res = await retriveByControlright(params);
      // console.log('查询监控信息', params, res);
      this.dataSource = res.data;
    },

    // 工单历史
    getRepairHistoryTable() {
      let vin = this.remindData.vin;
      // 增加参数 过滤 2年内单据
      let type = 'twoYear';
      this.fetchParams2 = Object.assign({}, { vin, type }, { xhrAbort: false });
      // console.log(this.dataList2,'shuju')
      // console.log(this.columns2)
    },

    // 服务活动
    async queryActivityValid() {
      const params = {
        sort: 'IS_VALID',
        order: 'asc',
        engineNo: this.remindData.engineNo || '',
        MODEL: this.remindData.modelCode || '',
        SERIES: this.remindData.seriesCode || '',
        RONO: this.remindData.roNo || '',
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        BRAND: this.remindData.brandCode || '',
        MILEAGE: this.remindData.lastMaintainMileage,
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        dmsFuncId: '35100010',
        _: '1567144192282'
      };
      const res = await queryActivityValid(params);
      // console.log('查询可选活动', params, res);
      this.dataSource3 = res.data;
    },

    // 保存
    async saveMsg() {
      if (this.isTrace === 80581003 || this.isTrace === 80581004) {
        this.$emit('closeDialog', false);
        return;
      }
      if (this.type == 2) {
        let remindContent = this.$refs.toggleText.remindContent;
        let customerFeedback = this.$refs.toggleText.customerFeedback;
        let formList3 = this.$refs.toggleText.formList3;
        console.log(formList3, 'formlist');
        let remindStatus = formList3.find(x => x.fieldName === 'remindStatus').initialValue;
        this.flag = true;
        if (!remindContent || !remindStatus) {
          this.flag = false;
        }
        if (remindStatus === 80571001) {
          if (!formList3.find(x => x.fieldName === 'nextRemindDate').initialValue) {
            this.flag = false;
          }
        } else if (remindStatus === 80571002) {
          if (!formList3.find(x => x.fieldName === 'remindFailReason').initialValue) {
            this.flag = false;
          }
        }
        if (this.flag) {
          let obj = {
            remindSource: this.remindSource || '1',
            ownerNo: this.remindData.ownerNo,
            vin: this.remindData.vin,
            remindContent,
            customerFeedback,
            remark: formList3.find(x => x.fieldName === 'remark').initialValue,
            remindStatus, //  提醒状态
            remindFailReason: formList3.find(x => x.fieldName === 'remindFailReason').initialValue || null,
            remindDate: formList3.find(x => x.fieldName === 'nextRemindDate').initialValue,
            remindWay: formList3.find(x => x.fieldName === 'remindWay').initialValue || null,
            insuranceMonth: formList3.find(x => x.fieldName === 'expiredMonth').initialValue, // 保险到期月
            insuranceDay: formList3.find(x => x.fieldName === 'expiredDay').initialValue, // 保险到期日
            company: formList3.find(x => x.fieldName === 'intentInsurance').initialValue // 意向保险公司
          };
          console.log(obj, 'obj');
          obj = JSON.parse(JSON.stringify(obj));
          const res = await addRemind(obj);
          if (res.resultCode === 200) {
            this.$notify.success({ title: '提示信息', message: '保存成功！' });
            this.$emit('close', false);
          }
          console.log(res, 'res');
        } else {
          this.$message({
            type: 'warning',
            message: '请填写必填项!'
          });
        }
      } else if (this.type == 1) {
        let tableList = this.$refs.ToggleTable.tableList;
        let formList = this.$refs.ToggleTable.formList3;
        // 当问卷类型设置的为必填项时，跟踪状态选择成功结束跟踪或者失败结束跟踪时，需要判断必填项的答案要必填，没有填需要弹出提示信息不能保存，当跟踪状态选择未跟踪或者继续跟踪时，答案选项可以不填。
        console.log(tableList, 'tablelist');
        console.log(formList, 'formList');
        tableList.forEach(x => {
          // console.log(x, 'xxxx');
          let traceStatus = formList.find(x => x.fieldName === 'traceStatus').initialValue;
          if (x.isMustFilled === 10041001 && (traceStatus === 80581003 || traceStatus === 80581004)) {
            if (!x.answer) {
              this.isMustFlag = false;
              return;
            } else {
              this.isMustFlag = true;
            }
          }
        });
        if (this.isMustFlag) {
          this.saveBtn();
        } else {
          this.$message({
            type: 'warning',
            message: '请填写必填项!'
          });
        }
      }
    },

    async saveBtn() {
      let questionnaireId = this.$refs.ToggleTable.questionnaireId;
      let tableList = this.$refs.ToggleTable.tableList;
      let formList = this.$refs.ToggleTable.formList3;
      let obj = {
        questionRecordDTOS: tableList, //  问卷信息table
        itemId: this.remindData.item_id || this.remindData.TRACE_ITEM_ID, //  客户流失主键ID
        questionnaireId: questionnaireId || null, //  问卷选择
        traceStatus: formList.find(x => x.fieldName === 'traceStatus').initialValue, //  跟踪状态
        drCode: formList.find(x => x.fieldName === 'reviewFailed').initialValue, //  回访失败原因
        isTraceVehiele: formList.find(x => x.fieldName === 'isTraceVehiele').initialValue, //  是否三日电访
        nextRepairRemind: formList.find(x => x.fieldName === 'nextRepairRemind').initialValue, //  下次维修提醒
        remark: formList.find(x => x.fieldName === 'remark').initialValue, //  备注
        roNo: this.remindData.roNo || ''
      };
      obj = JSON.parse(JSON.stringify(obj));
      console.log(obj);
      const res = await addQuestion(obj);
      if (res.resultCode === 200) {
        this.$notify.success({ title: '提示信息', message: '保存成功！' });
        this.$emit('close', false);
      }
      console.log(res, 'res');
    },

    // 取消
    closeDialog() {
      this.$emit('close', false);
    }
  }
};
</script>
<style lang="less" scoped>
.remindInput {
  width: 100%;
  .left {
    width: 27%;
    float: left;
    .detail_main {
      border: 1px solid #ebeef5;
      margin-bottom: 10px;
      .detail_top {
        background: #f2f2f2;
        border-bottom: 1px solid #ebeef5;
        height: 25px;
        line-height: 25px;
        padding: 0 4px;
        padding-right: 2px;
      }
      .detail_containter {
        padding-top: 10px;
      }
    }
  }
  .right {
    width: 73%;
    float: left;
    box-sizing: border-box;
    padding: 0 4px;
    .detail_main {
      border: 1px solid #ebeef5;
      margin-bottom: 10px;
      .detail_top {
        background: #f2f2f2;
        border-bottom: 1px solid #ebeef5;
        height: 25px;
        line-height: 25px;
        padding: 0 10px;
        padding-right: 10px;
      }
      .detail_containter {
        padding-top: 10px;
      }
    }
  }
}
</style>
